// pages/myArmy/myArmy.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    corps: {}
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: app.globalData.prefix + "/corpsAction/my.do",
      data: {
        openId: app.globalData.userInfo.openId
      },
      success: (res) => {
        let status = res.data.status
        if (status == "00") {
          let data = res.data.result
          let inCrops = data.inCorps
          if (inCrops) {
            this.setData({
              corps: data.corps
            })
          } else {
            wx.redirectTo({
              url: '../solidList/solidList'
            })
          }
        } else {
          wx.$showToast(res.data.errorMsg)
        }
      }
    })
  },
  bindchange(e) {
    let show = e.detail.value
    wx.request({
      url: app.globalData.prefix + "/corpsAction/changeShow.do",
      data: {
        openId: app.globalData.userInfo.openId,
        show: show
      },
      method: 'POST',
      success: (res) => {
        let status = res.data.status
        let corps = this.data.corps
        if (status == "00") {
          corps.show = show
          wx.$showToast(res.data.result)
        } else {
          wx.$showToast(res.data.errorMsg)
        }
        this.setData({
          corps: corps
        })
      }
    })
  },
  go(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.src+'?corpsId='+this.data.corps.corpsId+'&name='+this.data.corps.name
    })
  }
})